/*
 * Copyright (c) 2015 Uwantsoft Ltd.
 * www.uwantsoft.com
 * All rights reserved.
 * This software is the confidential and proprietary information of
 * You shall not disclose such Confidential Information and shall use
 * it only in accordance with the terms of the license agreement you
 * entered into with Uwantsoft.
 */

package com.uwantsoft.business.infrastructure.repository;

import com.uwantsoft.business.facade.dto.parking.CityOverviewQueryCondition;
import com.uwantsoft.business.infrastructure.repository.querier.CityOverviewQuerier;
import com.uwantsoft.business.service.domain.city.City;
import com.uwantsoft.business.service.infrastructure.CityRepository;
import com.uwantsoft.util.HibernateEntityRepository;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * @author Leipeichen.
 */
@SuppressWarnings("unchecked")
@Repository(value = "hibernateCityRepository")
public class HibernateCityRepository extends HibernateEntityRepository implements CityRepository {

    @Override
    public List<City> findCities(CityOverviewQueryCondition cityOverviewQueryCondition) {
        CityOverviewQuerier cityOverviewQuerier = new CityOverviewQuerier(getHibernateTemplate(), cityOverviewQueryCondition);
        return cityOverviewQuerier.getResults();
    }

    @Override
    public int findCityTotalAmount(CityOverviewQueryCondition condition) {
        CityOverviewQuerier cityOverviewQuerier = new CityOverviewQuerier(getHibernateTemplate(),condition);
        return cityOverviewQuerier.getAmount();
    }

    @Override
    public List<City> findCities() {
       return (List<City>)getHibernateTemplate().find("from City c where c.active=true");
    }
}
